package com.stm.bi.constant;

import com.stm.bi.dto.query.GroupField;
import com.stm.saas.dto.vo.IndexVO;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static com.stm.bi.constant.GroupTypeConstants.AVG;
import static com.stm.bi.constant.GroupTypeConstants.SUM;
import static com.stm.bi.constant.IndexConstants.*;

public class SalesTrendConstants {

    public static final String ORGANIZATION = "organization";

    public static final String CUSTOMER = "customer";

    public static final String CUSTOMER_GROWTH = "customer_growth";

    public static final String REGION = "region";
    public static final String REGION_REGION = "region_region";
    public static final String REGION_PROVINCE = "region_province";
    public static final String REGION_CITY = "region_city";
    public static final String REGION_DISTRICT = "region_district";

    public static final String FORMAT = "format";
    public static final String FORMAT_COOPERATIVE = "format_cooperative";
    public static final String FORMAT_LIFE = "format_life";
    public static final String FORMAT_LIFE_CODE = "offline_life_format";
    public static final String FORMAT_CHANNEL = "format_channel";
    public static final String FORMAT_INVESTMENT = "format_investment";


    public static final String PROD = "prod";
    public static final String PROD_CATEGORY = "prod_category";
    public static final String PROD_ASSORTMENT = "prod_assortment";
    public static final String PROD_STYLE = "prod_style";
    public static final String PROD_TYPE = "prod_type";

    public static final String SALES_INDEX = "1000";
    public static final String SALES_INDEX_TYPE1 = "1001";
    public static final String SALES_INDEX_TYPE2 = "1002";
    public static final String SALES_INDEX_TYPE3 = "1003";
    public static final String QTY_INDEX = "2000";
    public static final String QTY_INDEX_TYPE1 = "2001";

    public static final Map<String, IndexVO> INDEX_FIELD_MAP = new HashMap<>(){{
        put(SALES_INDEX, SALES_AMOUNT);
        put(QTY_INDEX, QTY);
    }};

    public static final Map<String, String> DICT_MAP = new HashMap<>(){{
        put(FORMAT_COOPERATIVE, "shop_cooperation_format");
        put(FORMAT_LIFE, "shop_life_format");
        put(FORMAT_INVESTMENT, "shop_invest_format");
    }};

    public static final Map<String, List<String>> FIELD_MAP = new HashMap<>(){{
        put(REGION_REGION, List.of(REGION_CODE_FIELD, REGION_NAME_FIELD));
        put(REGION_PROVINCE, List.of(PROVINCE_CODE_FIELD, PROVINCE_NAME_FIELD));
        put(REGION_CITY, List.of(CITY_CODE_FIELD,CITY_NAME_FIELD));
        put(REGION_DISTRICT, List.of(DISTRICT_CODE_FIELD, DISTRICT_NAME_FIELD));
        put(FORMAT_COOPERATIVE, List.of(COOPERATIVE_CODE_FIELD, COOPERATIVE_NAME_FIELD));
        put(FORMAT_LIFE, List.of(LIFE_CODE_FIELD, LIFE_NAME_FIELD));
        put(FORMAT_CHANNEL, List.of(CHANNEL_CODE_FIELD, CHANNEL_NAME_FIELD));
        put(FORMAT_INVESTMENT, List.of(INVESTMENT_CODE_FIELD, INVESTMENT_NAME_FIELD));
        put(PROD_CATEGORY, List.of(CATEGORY_CODE_FIELD, CATEGORY_NAME_FIELD));
        put(PROD_ASSORTMENT, List.of(ASSORTMENT_CODE_FIELD, ASSORTMENT_NAME_FIELD));
        put(PROD_STYLE, List.of(STYLE_CODE_FIELD, STYLE_NAME_FIELD));
        put(PROD_TYPE, List.of(STYLE_TYPE_FIELD));
    }};


    public static final Map<String, String> TABLE_NAME = new HashMap<>(){{
        put(CUSTOMER_GROWTH, "ads_base_default_sales");
        put(REGION_REGION, "ads_base_region_sales");
        put(REGION_PROVINCE, "ads_base_province_sales");
        put(REGION_CITY, "ads_base_city_sales");
        put(REGION_DISTRICT, "ads_base_district_sales");
        put(ORGANIZATION, "ads_base_default_sales");
        put(FORMAT_COOPERATIVE, "ads_base_default_sales");
        put(FORMAT_LIFE, "ads_base_default_sales");
        put(FORMAT_CHANNEL, "ads_base_default_sales");
        put(FORMAT_INVESTMENT, "ads_base_default_sales");
        put(PROD_CATEGORY, "ads_base_product_multi_sales");
        put(PROD_ASSORTMENT, "ads_base_product_multi_sales");
        put(PROD_STYLE, "ads_base_product_multi_sales");
        put(PROD_TYPE, "ads_base_product_multi_sales");
    }};


    public static final Map<String, String> ATTD_TABLE_NAME = new HashMap<>(){{
        put(FORMAT_COOPERATIVE, "ads_attd_format_cooperative");
        put(FORMAT_LIFE, "ads_attd_format_life");
        put(FORMAT_CHANNEL, "ads_attd_format_channel");
        put(FORMAT_INVESTMENT, "ads_attd_format_investment");
        put(PROD_CATEGORY, "ads_base_product_inventory");
        put(PROD_ASSORTMENT, "ads_base_product_inventory");
        put(PROD_STYLE, "ads_base_product_inventory");
        put(PROD_TYPE, "ads_base_product_inventory");
    }};

    public static final Map<String, List<IndexVO>> INDEX_MAP = new HashMap<>(){{
        put(CUSTOMER, List.of(NEW_CUSTOMERS, OLD_CUSTOMERS));
        put(REGION + SALES_INDEX_TYPE1, List.of(SALES_AMOUNT, PER_CUSTOMER_TRANSACTION));
        put(REGION + SALES_INDEX_TYPE2, List.of(SALES_AMOUNT, NUMBER_OF_TRANSACTIONS));
        put(ORGANIZATION + SALES_INDEX_TYPE1, List.of(SALES_AMOUNT, PER_CUSTOMER_TRANSACTION));
        put(ORGANIZATION + SALES_INDEX_TYPE2, List.of(SALES_AMOUNT, NUMBER_OF_TRANSACTIONS));
        put(FORMAT + SALES_INDEX_TYPE1, List.of(SALES_AMOUNT, NUMBER_OF_TRANSACTIONS));
        put(FORMAT + SALES_INDEX_TYPE2, List.of(PER_CUSTOMER_TRANSACTION, NUMBER_OF_CONT_ORDER));
        put(FORMAT + SALES_INDEX_TYPE3, List.of(AVG_DAY_NUMBER_OF_TRANSACTIONS, AVG_PER_DAY_SALES_AMOUNT));
        put(PROD + SALES_INDEX_TYPE1, List.of(SALES_AMOUNT, PRICE_AVG));
        put(PROD + SALES_INDEX_TYPE2, List.of(AVG_DAY_QTY, AVG_PER_DAY_SALES_AMOUNT));
        put(PROD + QTY_INDEX_TYPE1, List.of(QTY, INVENTORY, DIGESTIBILITY));
    }};

    public static final Map<String, List<GroupField>> GROUP_FIELD_MAP = new HashMap<>(){{
        put(CUSTOMER, List.of(GroupField.of(NEW_CUSTOMERS_FILED, SUM), GroupField.of(OLD_CUSTOMERS_FILED, SUM)));
        put(REGION, List.of(GroupField.of(SALES_AMOUNT_FIELD, SUM), GroupField.of(NUMBER_OF_TRANSACTIONS_FIELD, SUM), GroupField.of(AVG_DAY_NUMBER_OF_TRANSACTIONS_FIELD, SUM)));
        put(ORGANIZATION, List.of(GroupField.of(SALES_AMOUNT_FIELD, SUM), GroupField.of(NUMBER_OF_TRANSACTIONS_FIELD, SUM), GroupField.of(AVG_DAY_NUMBER_OF_TRANSACTIONS_FIELD, SUM)));
        put(FORMAT, List.of(GroupField.of(SALES_AMOUNT_FIELD, SUM),
                GroupField.of(AVG_PER_DAY_SALES_FIELD, SUM),
                GroupField.of(NUMBER_OF_TRANSACTIONS_FIELD, SUM),
                GroupField.of(AVG_DAY_NUMBER_OF_TRANSACTIONS_FIELD, SUM),
                GroupField.of(NUMBER_OF_CONT_ORDER_FIELD, AVG)));
        put(PROD, List.of(GroupField.of(SALES_AMOUNT_FIELD, SUM),
                GroupField.of(AVG_PER_DAY_SALES_FIELD, SUM),
                GroupField.of(QTY_FIELD, SUM),
                GroupField.of(AVG_DAY_QTY_FIELD, SUM)));
    }};

    public static final Map<String, List<IndexVO>> TABLE_INDEX_MAP = new HashMap<>(){{
        put(CUSTOMER, Arrays.asList(NEW_CUSTOMERS, OLD_CUSTOMERS));
        put(REGION, Arrays.asList(SALES_AMOUNT, PER_CUSTOMER_TRANSACTION, AVG_DAY_NUMBER_OF_TRANSACTIONS));
        put(ORGANIZATION, Arrays.asList(SALES_AMOUNT, PER_CUSTOMER_TRANSACTION, AVG_DAY_NUMBER_OF_TRANSACTIONS));
        put(FORMAT, Arrays.asList(SALES_AMOUNT, PER_CUSTOMER_TRANSACTION, NUMBER_OF_CONT_ORDER, AVG_PER_DAY_SALES_AMOUNT, AVG_DAY_NUMBER_OF_TRANSACTIONS));
        put(PROD + SALES_INDEX, Arrays.asList(SALES_AMOUNT, PRICE_AVG, AVG_DAY_QTY, AVG_PER_DAY_SALES_AMOUNT));
        put(PROD + QTY_INDEX, Arrays.asList(QTY, INVENTORY, DIGESTIBILITY));
    }};

    public static final Map<String, String> ITEM_NAME_MAP = new HashMap<>(){{
        put(REGION_REGION, "区域名称");
        put(REGION_PROVINCE, "省份名称");
        put(REGION_CITY, "城市名称");
        put(REGION_DISTRICT, "行政区名称");
        put(ORGANIZATION, "部门名称");
        put(FORMAT_COOPERATIVE, "合作业态");
        put(FORMAT_LIFE, "生活业态");
        put(FORMAT_CHANNEL, "渠道业态");
        put(FORMAT_INVESTMENT, "投资业态");
        put(PROD_CATEGORY, "品类");
        put(PROD_ASSORTMENT, "品种");
        put(PROD_STYLE, "款式");
        put(PROD_TYPE, "款式类别");
    }};

}
